package com.lml.interviewTest;

import com.lml.entity.optionalTestEntity.Address;
import org.junit.jupiter.api.Test;

import java.lang.reflect.Field;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.Comparator;
import java.util.List;
import java.util.function.Function;

/**
 * @author luomingliang
 * @date 2021/7/14 20:06
 */
public class Test05 {

    public static void main(String[] args) {
    }

    @Test
    public void test01() {
        and(10);
    }

    @Test
    public void test02() {
        System.out.println(countOne(10));
        System.out.println(countOne(9));
        System.out.println(countOne(8));
        System.out.println(countOne(7));
        System.out.println(countOne(6));
    }

    public void and(int x) {
        for (int i = x; i > 0; i--) {
            System.out.println(i + "&" + (i - 1) + "=" + (i & (i - 1)));
        }
    }

    public int countOne(int num) {
        int count = 0;
        while (num != 0) {
            num = num & (num - 1);
            count++;
        }
        return count;
    }
}